package skill;

public class nextPermutation {
    public void nextPermutation(int[] nums) {
        int i = nums.length - 2;
        while (i >= 0 && nums[i] >= nums[i + 1]) {
            i--;
        }
        if (i >= 0) {
            int j = nums.length - 1;
            while (j >= 0 && nums[j] >= nums[j + 1]) {
                j--;
            }
            swap(nums, i, j);
        }
    }
    public void swap(int[]nums,int i,int j){
        int temp=nums[i];
        nums[i]=nums[j];
        nums[j]=temp;
    }
    public void reverse(int []nums,int start){
        for(int i=0;i<(nums.length-start)/2;i++){
            swap(nums, i+start, nums.length-1-i);
        }
    }

    public static void main(String[] args) {

    }
}
